<!DOCTYPE html>
<head>
  <meta charset="UTF-8">
  <meta name="referrer" content="no-referrer">
  <style>
    #map {
      height: 1800px;
      width: 100%;
      margin: 0 auto;
    }
  </style>
  <script src="https://mapapi.cloud.huawei.com/mapjs/v1/api/js?callback=initMap&key=DAEDAFzQsAcJf9i2q33pu5afKkcxA0FxcRhfqx89KtwmYgdXPdCtAFplg4Qgq4OGCzotVw0wz51yNYtdpOUEOqvPSiavc4APN41Ftw%3D%3D"></script>
</head>
<body>
<div id="map"></div>
<script>
 // var APIKEY=encodeURI("DAEDAFzQsAcJf9i2q33pu5afKkcxA0FxcRhfqx89KtwmYgdXPdCtAFplg4Qgq4OGCzotVw0wz51yNYtdpOUEOqvPSiavc4APN41Ftw==");
  //document.write('<script type="text/javascript" src="https://mapapi.cloud.huawei.com/mapjs/v1/api/js?callback=initMap&key='+APIKEY+'"><\/script>');
 var map;
 var directionsService;
 var directionsRenderer;
 // 创建路径规划请求体
 function initMap() {
    var mapOptions = {};
    // 设置地图中心点坐标 123.373200,41.801260
    mapOptions.center = {lat: 41.801260 , lng:123.373200 };
    // 设置地图初始化缩放级别
    mapOptions.zoom = 20;
    // 设置地图语言
    mapOptions.language='zh';
    // 设置地图加载时使用的瓦片类型，支持vector（矢量）或raster（栅格）
    mapOptions.sourceType = 'vector';
    mapOptions.locationControl=true;
    mapOptions.rotateControl=true;
    // 创建地图对象
     map = new HWMapJsSDK.HWMap(document.getElementById('map'), mapOptions);
    directionsService = new HWMapJsSDK.HWDirectionsService();
    directionsRenderer = new HWMapJsSDK.HWDirectionsRenderer();
   directions();
  }
  function directions(){
      // 创建路径规划请求体
      var DirectionsRequest = {};
      DirectionsRequest.origin ={lat: 41.801260 , lng:123.373200 }

      DirectionsRequest.destination = {lat: 41.801260 , lng:123.373800 }
     var markerOrigin = new HWMapJsSDK.HWMarker({
      position: DirectionsRequest.origin,
      label: '起点'
     });

    var markerDestination = new HWMapJsSDK.HWMarker({
      position: DirectionsRequest.destination,
      label: '终点'
    });

    markerOrigin.setMap(map);
    markerDestination.setMap(map);
    // 调用路径规划接口
    directionsService.routeDriving(DirectionsRequest, callback);
    directionsRenderer.setMap(map);
    // 通过回调函数获取路径规划结果
    function callback(DirectionsResult, DirectionsStatus) {
      if (DirectionsStatus == '0') {
        // 通过HWDirectionsRenderer对象渲染路径
        directionsRenderer.setDirections(DirectionsResult);
      }
    }
  }


</script>
</body>


